#include "mediatorsmanager.h"
#include "dictionarymediator.h"
#include "word.h"
#include "dictionary.h"

using namespace qWordCards;

MediatorsManager::MediatorsManager() : QObject(0) {
}

Word MediatorsManager::GetWord() const {
	return Word(); // stub
}

int MediatorsManager::GetFavouriteWordsCount() const {
	int count;
	foreach (DictionaryMediator* m, _mediators) {
		if (m->GetDictionary()->IsUsed()) {
			count += m->GetFavouriteWordsCount();
		}
	}
	return count;
}

int MediatorsManager::GetForbiddenWordsCount() const {
	int count;
	foreach (DictionaryMediator* m, _mediators) {
		if (m->GetDictionary()->IsUsed()) {
			count += m->GetForbiddenWordsCount();
		}
	}
	return count;
}

int MediatorsManager::GetRegularWordsCount() const {
	int count;
	foreach (DictionaryMediator* m, _mediators) {
		if (m->GetDictionary()->IsUsed()) {
			count += m->GetRegularWordsCount();
		}
	}
	return count;
}

void MediatorsManager::sl_DictionaryCreated(const Dictionary* const d) {
	DictionaryMediator* m = new DictionaryMediator(d);
	_mediators.insert(m);
}

void MediatorsManager::sl_AboutToDeleteDictionary(const Dictionary* const d) {
	foreach (DictionaryMediator* m, _mediators) {
		if (m->GetDictionary() == d) {
			_mediators.removeAll(m);
			delete m;
			return;
		}
	}
}
